package com.example.administrator.widgettest419szy;

import android.content.Intent;
import android.provider.Telephony;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Checkable;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class sunzhiyong419 extends AppCompatActivity implements View.OnClickListener{
private TextView tv;
    private EditText et;
    private Button btext,btimg;
    private ImageView iv;
    private ImageButton ibtn;
    private RadioGroup rg;
    private RadioButton rbnan,rbnv ;
    private CheckBox cblan,cbzu,cbping;
    private Button btngetgender,btngetfun;
    private String strfun="";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sunzhiyong419);
        init();
    }
    private void init(){
//6控件
        tv=(TextView)findViewById(R.id.textView);
        et=(EditText) findViewById(R.id.editText);
        btext=(Button) findViewById(R.id.button);
        btimg=(Button)findViewById(R.id.button2);
        iv=(ImageView) findViewById(R.id.imageView);
        ibtn=(ImageButton) findViewById(R.id.imageButton);
        //
        btext.setOnClickListener(this);
        btimg.setOnClickListener(this);
        ibtn.setOnClickListener(this);
        rg=(RadioGroup)findViewById(R.id.RadioGroup);
        rbnan=(RadioButton)findViewById(R.id.radioButton6);
        rbnv=(RadioButton)findViewById(R.id.radioButton5);
      cblan=(CheckBox)findViewById(R.id.checkBox7);
        cbzu=(CheckBox)findViewById(R.id.checkBox6);
        cbping=(CheckBox)findViewById(R.id.checkBox5);
       btngetgender=(Button)findViewById(R.id.button5);
        btngetfun=(Button)findViewById(R.id.button7);

        btngetgender.setOnClickListener(this);
        btngetfun.setOnClickListener(this);
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId)
        {
            case  R.id.radioButton6:
            tv.setText("男");
            break;
            case  R.id.radioButton5:
                tv.setText("女");
                break;

        }
    }
});
        cblan.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked)
                    strfun+="篮球+";
                else
                    strfun=strfun.replace("篮球+","");
                tv.setText(strfun);
            }
        });
        cbzu.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked)
                    strfun+="足球+";
                else
                    strfun=strfun.replace("足球+","");
                tv.setText(strfun);
            }
        });
        cbping.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked)
                    strfun+="乒乓球+";
                else
                    strfun=strfun.replace("乒乓球+","");
                tv.setText(strfun);
            }
        });
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.button://设置文本
                String str=et.getText().toString();
                tv.setText(str);
                break;
            case R.id.button2://设置图片
                iv.setImageResource(R.drawable.su1);
                break;
            case R.id.imageButton://图片按钮
                Intent intent=new Intent(sunzhiyong419.this,NewActivity.class);


                intent.putExtra("param1",et.getText().toString());
                intent.putExtra("param2",3);
                startActivity(intent);
                break;
            case R.id.button5:
                if(rbnan.isChecked()) tv.setText("男");
                if(rbnv.isChecked()) tv.setText("女");
                break;
            case R.id.button7:
                String mgs="";
                if(cblan.isChecked()) mgs+="篮球";
                if(cbping.isChecked()) mgs+="乒乓球";
                if(cbzu.isChecked()) mgs+="足球";
                tv.setText(mgs);
                break;
        }
    }
}
